package com.songjia.springboot.configurationProperties;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 代码说明：测试配置文件controller
 *
 */
@RestController
public class PropertiesController {
	
	@Autowired
	private ApplicationSettings applicationSettings;
	
	@Autowired
	private JdbcConnectionSettings jdbcConnectionSettings;
	
	/**
     * spring boot会自动读取application.properties,
     * 并且将其作为系统参数进行注入,用户也可以在启动应用的时候
     * 通过-Dname=xxx来手动注入，手动注入会覆盖配置文件中的参数,
     * 如果没有指定值，那么testValue的默认值就是World。
     */
	@Value("${testValue:songjia}")
	private String testValue;
	
	@RequestMapping("/properties")
	public String properties() {
		System.out.println(applicationSettings.getName()+"---"+applicationSettings.getAge());  
		return applicationSettings.getName()+"---"+applicationSettings.getAge(); 
	}
	
	@RequestMapping("/value")
	public String value() {
		//输出结果为：tomtopwebsite123--jdbc:postgresql://192.168.220.52:5432/base--tomtopwebsite
		System.out.println(jdbcConnectionSettings.getBasePassword()+"--"+jdbcConnectionSettings.getBaseUrl()+"--"+jdbcConnectionSettings.getBaseUsername());
		return jdbcConnectionSettings.getBasePassword()+"--"+jdbcConnectionSettings.getBaseUrl()+"--"+jdbcConnectionSettings.getBaseUsername();
	}
	
	@RequestMapping("/testValue")
	public String testValue() {
		return String.format("hello:%s", testValue);
	}
}
